package com.wyl.studyredis.framework.util;

import cn.hutool.core.bean.BeanUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 吴宇亮 on 2022/2/11 13:57
 */
public class _BeanUtil {

    public static <Type> Type copyProperties(Object source, Class<Type> targetClass) throws InstantiationException, IllegalAccessException {
        if(source == null){
            return null;
        }
        Type target = targetClass.newInstance();
        BeanUtil.copyProperties(source, target);
        return target;
    }

    public static <Type> List<Type> copyList(List sourceCollection, Class<Type> targetClass) throws InstantiationException, IllegalAccessException {
        if(sourceCollection == null){
            return null;
        }
        List<Type> result = new ArrayList<>(sourceCollection.size());
        for (Object source : sourceCollection) {
            result.add(copyProperties(source, targetClass));
        }
        return result;
    }
}
